package cn.nohan.funplay.module.member.mongo.config;

import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;

/**
 * @author caozhipeng
 * @date 2025/7/18
 */
@EnableWebMvc
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

//    @Override
//    public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
////		# com.chinaunicom.aurveyapp.app.result.HttpResult cannot be cast to java.lang.String
//        converters.add(0, new MappingJackson2HttpMessageConverter());
//    }

//    @Bean
//    public HttpMessageConverters cusHttpMessageConverter() {
//        return new HttpMessageConverters(new FastJsonHttpMessageConverter());
//    }


    @Autowired
    private ObjectMapper objectMapper;  // 注入自定义的ObjectMapper

    @Override
    public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
        // 添加自定义Jackson转换器
        MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
        converter.setObjectMapper(objectMapper);
        converters.add(converter);
    }
}
